package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: ShoppingCartController
 * @Author: YuanDing
 * @Date: 2024/2/6 17:34
 * @Description:
 */

@Api("用户端购物车")
@RestController
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 添加或更新购物车
     * @param shoppingCartDTO
     * @return
     */
    @ApiOperation("添加或更新购物车")
    @PostMapping("/add")
    public Result addOrUpdateShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        shoppingCartService.addOrUpdateShoppingCart(shoppingCartDTO);
        return Result.success();
    }

    @ApiOperation("获取用户购物车列表")
    @GetMapping("/list")
    public Result list() {
        Result result = shoppingCartService.list();
        return result;
    }

    @ApiOperation("购物车数量减减")
    @PostMapping("/sub")
    public Result subShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        shoppingCartService.subShoppingCart(shoppingCartDTO);
        return Result.success();
    }

    @ApiOperation("清空购物车")
    @DeleteMapping("/clean")
    public Result cleanShoppingCart() {
        shoppingCartService.clean();
        return Result.success();
    }

}
